﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using Model;

namespace TanHungLong
{
    public partial class FrmXuatNhapTon : DevExpress.XtraEditors.XtraForm
    {
        #region variant
        private bool allowCloseForm = true;
        private bool khoaBtnSave = false;
        private MatHangBOCollection matHangBOColl = MatHangBOCollection.GetMatHangBOCollection();
        private GiaBOCollection giaMatHangBoColl = GiaBOCollection.GetGiaBOCollection();
        private XuatNhapTonBOCollection xuatNhapTonBOCollection = XuatNhapTonBOCollection.NewXuatNhapTonBOCollection();
        private XuatNhapTonCTBOCollection xuatNhapTonCTBOCollection = XuatNhapTonCTBOCollection.NewXuatNhapTonCTBOCollection();
        private TonKhoBOCollection tonKhoBOCollection = TonKhoBOCollection.NewTonKhoBOCollection();
        private XuatNhapTonBO xuatNhapTonBO = XuatNhapTonBO.NewRootXuatNhapTonBO();

        #endregion variant

        //=====================================
        #region form
        public FrmXuatNhapTon()
        {
            InitializeComponent();
            this.KeyPreview = true;

            this.Load += new EventHandler(FrmXuatNhapTon_Load);
            this.FormClosing += new FormClosingEventHandler(FrmXuatNhapTon_FormClosing);
            this.btnHuy.Click += new EventHandler(btnHuy_Click);
            this.btnTimKiem.Click += new EventHandler(btnTimKiem_Click);
            this.btnClose.Click += new EventHandler(btnClose_Click);
            this.grdViewXuatNhapTon.RowCellStyle += new RowCellStyleEventHandler(grdView_RowCellStyle);
            this.grdViewXuatNhapTon.ShowingEditor += new CancelEventHandler(grdView_ShowingEditor);

            this.grdViewXuatNhapTon.RowCellClick += new RowCellClickEventHandler(grdViewXuatNhapTon_RowCellClick);
        }

        private void FrmXuatNhapTon_Load(object sender, EventArgs e)
        {
            RefreshData();
            //SetFormStatus(this.formStatus);

            Utility.InitControl(this.lookUpEditKhoID);

            Utility.InitControl(this.reLookUpKhoID);


        }

        private void FrmXuatNhapTon_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.allowCloseForm == false)
                e.Cancel = true;
        }

        #endregion form

        //=====================================
        #region control

        #endregion control

        //=====================================
        #region button
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            RefreshData();
        }


        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        #endregion button

        //=====================================
        #region grid

        private void grdViewXuatNhapTon_RowCellClick(object sender, RowCellClickEventArgs e)
        {
            try
            {
                int XuatNhapTonID = StaticUtil.GetInt(grdViewXuatNhapTon.GetFocusedRowCellValue("XuatNhapTonID"));
                this.xuatNhapTonBO = Model.XuatNhapTonBO.GetRootXuatNhapTonBO(XuatNhapTonID);
                this.xuatNhapTonCTBOCollection = Model.XuatNhapTonCTBOCollection.GetXuatNhapTonCTBOCollection("XuatNhapTonID = " + XuatNhapTonID.ToString());
                this.bdSourceXuatNhapTonCT.DataSource = this.xuatNhapTonCTBOCollection;
                khoaBtnSave = true;
            }
            catch { }
        }

        private void grdView_ShowingEditor(object sender, CancelEventArgs e)
        {
            GridView grdView = (GridView)sender;

            bool del = StaticUtil.GetBool(grdView.GetFocusedRowCellValue("DELE"));
            string fieldName = grdView.FocusedColumn.FieldName;

            if (del && fieldName != "DELE")
                e.Cancel = true;
            else
                if (fieldName == "DELE" && grdView.FocusedRowHandle == GridControl.NewItemRowHandle)
                    e.Cancel = true;
        }

        private void grdView_RowCellStyle(object sender, RowCellStyleEventArgs e)
        {
            bool del = StaticUtil.GetBool(this.grdViewXuatNhapTon.GetRowCellValue(e.RowHandle, "DELE"));

            if (del)
            {
                e.Appearance.Font = MyStyle.DELETE_FONT;
                e.Appearance.ForeColor = MyStyle.DELETE_COLOR;
            }
        }

        #endregion grid

        //=====================================
        #region function

        private void ResetData()
        {
            lookUpEditKhoID.EditValue = null;
            this.xuatNhapTonBO = Model.XuatNhapTonBO.NewRootXuatNhapTonBO();
            this.xuatNhapTonCTBOCollection = Model.XuatNhapTonCTBOCollection.NewXuatNhapTonCTBOCollection();
        }

        private void RefreshData()
        {
            #region

            DanhMucBOList khoBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.DanhMucKho);
            Utility.SetData(this.reLookUpKhoID, khoBOList, khoBOList.Count);
            Utility.SetData(this.lookUpEditKhoID, khoBOList, khoBOList.Count);

            dateEditTungay.DateTime = dateEditDenngay.DateTime = DateTime.Now;
            #endregion BOList

            ResetData();

            this.bdSourceXuatNhapTon.DataSource = this.xuatNhapTonBOCollection.Clone();
            this.bdSourceXuatNhapTonCT.DataSource = this.xuatNhapTonCTBOCollection.Clone();

        }

        #endregion function


        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            string strWhere = "XuatNhapTonID >= 0";

            if (checkNgay.Checked)
            {
                strWhere = strWhere + " and (convert(nvarchar,TuNgay,111) >= '" + dateEditTungay.DateTime.ToString("yyyy/MM/dd") + "') and (convert(nvarchar,DenNgay,111) <= '" + dateEditDenngay.DateTime.ToString("yyyy/MM/dd") + "')";
            }

            if (checkKhachHang.Checked)
                if (lookUpEditKhoID.EditValue != null)
                {
                    strWhere = strWhere + " and KhoID = " + lookUpEditKhoID.EditValue.ToString();
                }
            timKiem(strWhere);
        }


        private void timKiem(string strwhere)
        {
            xuatNhapTonBOCollection = XuatNhapTonBOCollection.GetXuatNhapTonBOCollection(strwhere, "XuatNhapTonID", "DESC");
            this.bdSourceXuatNhapTon.DataSource = this.xuatNhapTonBOCollection.Clone();

        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            RefreshData();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (khoaBtnSave == false)
                {
                    xuatNhapTonBO.Save();
                    int recordCountXuat = xuatNhapTonCTBOCollection.Count;
                    if (recordCountXuat > 0)
                    {
                        for (int i = 0; i < recordCountXuat; i++)
                        {
                            xuatNhapTonCTBOCollection[i].XuatNhapTonID = xuatNhapTonBO.XuatNhapTonID.Value;
                        }
                    }
                    xuatNhapTonCTBOCollection.Save();
                }
                string tungay = "Từ ngày: " + xuatNhapTonBO.TuNgay.Value.ToString("dd/MM/yyyy") + " Đến ngày: " + xuatNhapTonBO.DenNgay.Value.ToString("dd/MM/yyyy");
                string taikho = "Kho được tổng hợp: " + DanhMucBO.GetRootDanhMucBO(xuatNhapTonBO.KhoID.Value).NoiDung;
                Report.rpXuatNhapTon rXuatNhapTon = new Report.rpXuatNhapTon(tungay, taikho, xuatNhapTonCTBOCollection);
                rXuatNhapTon.ShowPreviewDialog();
                btnTimKiem_Click(e, e);
            }
            catch { }
        }


        private void btnAdd_Click(object sender, EventArgs e)
        {

            DateTime tungay = dateEditTungay.DateTime;
            DateTime denngay = dateEditDenngay.DateTime;
            DateTime hiennay = Session.NgayHeThong;
            try
            {
                if (kiemtraLuu() > 0)
                {
                    khoaBtnSave = false;
                    xuatNhapTonBO = XuatNhapTonBO.NewRootXuatNhapTonBO();
                    xuatNhapTonCTBOCollection = XuatNhapTonCTBOCollection.NewXuatNhapTonCTBOCollection();

                    #region Xuất Nhập Tồn BO

                    xuatNhapTonBO.KhoID = StaticUtil.GetInt(lookUpEditKhoID.EditValue, -1);
                    xuatNhapTonBO.TuNgay = dateEditTungay.DateTime;
                    xuatNhapTonBO.DenNgay = dateEditDenngay.DateTime;

                    #endregion

                    #region Xuất trong kỳ
                    string strWhereXuat = "(TinhTrangXuatKho = 1) and (convert(nvarchar,NgayLapHoaDon,111) >= '" + tungay.ToString("yyyy/MM/dd") + "') and (convert(nvarchar,NgayLapHoaDon,111) < '" + denngay.ToString("yyyy/MM/dd") + "')";
                    HoaDonBanBOCollection hoaDonBanBOCollection = HoaDonBanBOCollection.GetHoaDonBanBOCollection(strWhereXuat);
                    string listIDXuat = "";
                    int recordCountXuat = hoaDonBanBOCollection.Count;
                    if (recordCountXuat > 0)
                    {
                        for (int i = 0; i < recordCountXuat; i++)
                        {
                            object _idVattu = hoaDonBanBOCollection[i].HoaDonBanID;
                            listIDXuat += _idVattu.ToString() + ",";
                        }
                    }
                    HoaDonBanChiTietBOCollection hoaDonBanChitietBOCollection =
                        HoaDonBanChiTietBOCollection.NewHoaDonBanChiTietBOCollection();
                    if (listIDXuat != "")
                    {
                        strWhereXuat = " HoaDonBanID in ('" + listIDXuat.Replace(",", "','") + "')";
                        hoaDonBanChitietBOCollection =
                            HoaDonBanChiTietBOCollection.GetHoaDonBanChiTietBOCollection(strWhereXuat);
                    }
                    #endregion

                    #region Nhập trong kỳ
                    string strWhereNhap = "(TinhTrangXuatKho = 1) and (convert(nvarchar,NgayLapHoaDon,111) >= '" + tungay.ToString("yyyy/MM/dd") + "') and (convert(nvarchar,NgayLapHoaDon,111) < '" + denngay.ToString("yyyy/MM/dd") + "')";
                    PhieuNhapBOCollection phieuNhapBOCollection = PhieuNhapBOCollection.GetPhieuNhapBOCollection(strWhereNhap);
                    string listIDNhap = "";
                    int recordCountNhap = phieuNhapBOCollection.Count;
                    if (recordCountNhap > 0)
                    {
                        for (int i = 0; i < recordCountNhap; i++)
                        {
                            object _idVattu = phieuNhapBOCollection[i].PhieuNhapID;
                            listIDNhap += _idVattu.ToString() + ",";
                        }
                    }
                    PhieuNhapChiTietBOCollection phieuNhapChitietBOCollection =
                        PhieuNhapChiTietBOCollection.NewPhieuNhapChiTietBOCollection();
                    if (listIDNhap != "")
                    {
                        strWhereNhap = " PhieuNhapID in ('" + listIDNhap.Replace(",", "','") + "')";
                        phieuNhapChitietBOCollection =
                            PhieuNhapChiTietBOCollection.GetPhieuNhapChiTietBOCollection(strWhereNhap);
                    }
                    #endregion

                    #region Chuyen doi Kho trong ky

                    string strWhereChuyenKho = " convert(nvarchar,DATC,111) >= '" + tungay.ToString("yyyy/MM/dd") + "' and convert(nvarchar,DATC,111) < '" + denngay.ToString("yyyy/MM/dd") + "' ";
                    ChuyenKhoBOCollection chuyenKhoBOCollection = ChuyenKhoBOCollection.GetChuyenKhoBOCollection(strWhereChuyenKho);

                    #endregion

                    #region Xuất ngoài kỳ
                    string strWhereXuatNK = "(TinhTrangXuatKho = 1) and (convert(nvarchar,NgayLapHoaDon,111) >= '" + denngay.ToString("yyyy/MM/dd") + "') and (convert(nvarchar,NgayLapHoaDon,111) < '" + hiennay.ToString("yyyy/MM/dd") + "')";
                    HoaDonBanBOCollection hoaDonBanBOCollectionNK = HoaDonBanBOCollection.GetHoaDonBanBOCollection(strWhereXuatNK);
                    string listIDXuatNK = "";
                    int recordCountXuatNK = hoaDonBanBOCollectionNK.Count;
                    if (recordCountXuatNK > 0)
                    {
                        for (int i = 0; i < recordCountXuatNK; i++)
                        {
                            object _idVattu = hoaDonBanBOCollectionNK[i].HoaDonBanID;
                            listIDXuatNK += _idVattu.ToString() + ",";
                        }
                    }
                    HoaDonBanChiTietBOCollection hoaDonBanChitietBOCollectionNK =
                        HoaDonBanChiTietBOCollection.NewHoaDonBanChiTietBOCollection();
                    if (listIDXuatNK != "")
                    {
                        strWhereXuatNK = " HoaDonBanID in ('" + listIDXuatNK.Replace(",", "','") + "')";
                        hoaDonBanChitietBOCollectionNK =
                            HoaDonBanChiTietBOCollection.GetHoaDonBanChiTietBOCollection(strWhereXuatNK);
                    }
                    #endregion

                    #region Nhập ngoài kỳ
                    string strWhereNhapNK = "(TinhTrangXuatKho = 1) and (convert(nvarchar,NgayLapHoaDon,111) >= '" + denngay.ToString("yyyy/MM/dd") + "') and (convert(nvarchar,NgayLapHoaDon,111) < '" + hiennay.ToString("yyyy/MM/dd") + "')";
                    PhieuNhapBOCollection phieuNhapBOCollectionNK = PhieuNhapBOCollection.GetPhieuNhapBOCollection(strWhereNhapNK);
                    string listIDNhapNK = "";
                    int recordCountNhapNK = phieuNhapBOCollectionNK.Count;
                    if (recordCountNhapNK > 0)
                    {
                        for (int i = 0; i < recordCountNhapNK; i++)
                        {
                            object _idVattu = phieuNhapBOCollectionNK[i].PhieuNhapID;
                            listIDNhapNK += _idVattu.ToString() + ",";
                        }
                    }
                    PhieuNhapChiTietBOCollection phieuNhapChitietBOCollectionNK =
                        PhieuNhapChiTietBOCollection.NewPhieuNhapChiTietBOCollection();
                    if (listIDNhapNK != "")
                    {
                        strWhereNhapNK = " PhieuNhapID in ('" + listIDNhapNK.Replace(",", "','") + "')";
                        phieuNhapChitietBOCollectionNK =
                            PhieuNhapChiTietBOCollection.GetPhieuNhapChiTietBOCollection(strWhereNhapNK);
                    }
                    #endregion

                    #region Chuyen doi Kho ngoai ky

                    string strWhereChuyenKhoNK = " convert(nvarchar,DATC,111) >= '" + denngay.ToString("yyyy/MM/dd") + "' and convert(nvarchar,DATC,111) < '" + hiennay.ToString("yyyy/MM/dd") + "' ";
                    ChuyenKhoBOCollection chuyenKhoBOCollectionNK = ChuyenKhoBOCollection.GetChuyenKhoBOCollection(strWhereChuyenKhoNK);

                    #endregion

                    #region Get Tồn kho hiện tại

                    TonKhoBOCollection tonKhoBOCollection = TonKhoBOCollection.GetTonKhoBOCollection("DanhMucKhoID = " + StaticUtil.GetInt(lookUpEditKhoID.EditValue, -1));

                    #endregion

                    DanhMucBOList donViTinhBOList = DanhMucBOList.GetDanhMucBOList(LoaiDanhMuc.DonViTinh);

                    #region Bắt đầu tạo Xuất Nhập tồn chi tiết

                    int dem = 1;
                    int recordCountKho = tonKhoBOCollection.Count;
                    if (recordCountKho > 0)
                    {
                        for (int i = 0; i < recordCountKho; i++)
                        {
                            XuatNhapTonCTBO tempBO = XuatNhapTonCTBO.NewRootXuatNhapTonCTBO();

                            tempBO.STT0 = dem;
                            //tempBO.IDTieuhao = TieuhaoBO.ID.Value;
                            tempBO.MatHangID = StaticUtil.GetInt(tonKhoBOCollection[i].MatHangID, -1);
                            tempBO.MaMatHang = TimMatHang(tempBO.MatHangID.Value, matHangBOColl)[0, 0].ToString();
                            tempBO.TenMatHang = TimMatHang(tempBO.MatHangID.Value, matHangBOColl)[0, 1].ToString();
                            tempBO.DonViTinhID = StaticUtil.GetInt(tonKhoBOCollection[i].DonViTinhID, -1);

                            int? _value = null;
                            _value = StaticUtil.GetRealInt(tempBO.DonViTinhID);
                            if (_value != null)
                                if (donViTinhBOList.ContainsKey(_value))
                                    tempBO.TenDonViTinh = donViTinhBOList.Value(_value);
                                else
                                    tempBO.TenDonViTinh = "";
                            tempBO.CuoiKyGia = TimGia(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, giaMatHangBoColl);

                            tempBO.CuoiKyTon = StaticUtil.GetDouble(tonKhoBOCollection[i].SoLuongTon, 0)
                                - TinhSLNhap(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, phieuNhapChitietBOCollectionNK)[0, 0]
                                + TinhSLXuat(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, hoaDonBanChitietBOCollectionNK)[0, 0]
                                + TinhSLDi(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, chuyenKhoBOCollectionNK)
                                - TinhSLDen(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, chuyenKhoBOCollectionNK);
                            tempBO.CuoiKyTien = tempBO.CuoiKyGia.Value * tempBO.CuoiKyTon.Value;


                            tempBO.TrongKyNhap = TinhSLNhap(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, phieuNhapChitietBOCollection)[0, 0]
                                + TinhSLDen(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, chuyenKhoBOCollection);
                            tempBO.TrongKyTienNhap = TinhSLNhap(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, phieuNhapChitietBOCollection)[0, 1];


                            tempBO.TrongKyXuat = TinhSLXuat(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, hoaDonBanChitietBOCollection)[0, 0]
                                + TinhSLDi(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, chuyenKhoBOCollection);
                            tempBO.TrongKyTienXuat = TinhSLXuat(tempBO.MatHangID.Value, tempBO.DonViTinhID.Value, hoaDonBanChitietBOCollection)[0, 1];

                            tempBO.DauKyTon = tempBO.CuoiKyTon.Value - tempBO.TrongKyNhap.Value + tempBO.TrongKyXuat.Value;

                            tempBO.GhiChu = "";

                            xuatNhapTonCTBOCollection.Add(tempBO);
                            dem = dem + 1;
                        }
                    }
                }

                bdSourceXuatNhapTonCT.DataSource = xuatNhapTonCTBOCollection.Clone();

                    #endregion
            }
            catch
            { }
        }

        //---- Tính số lượng nhập trong Phiếu nhập chi tiết 
        #region
        private double[,] TinhSLNhap(int _matHangID, int _donViTinhID, PhieuNhapChiTietBOCollection hdn)
        {
            double[,] _soluong = new double[1, 2];
            int recordCount = hdn.Count;
            if (recordCount > 0)
            {
                for (int i = 0; i < recordCount; i++)
                {
                    if ((hdn[i].MatHangID.Value == _matHangID) & (hdn[i].DonViTinhID.Value == _donViTinhID))
                    {
                        object _sl = hdn[i].SoLuong;
                        object _tt = hdn[i].ThanhTien;
                        _soluong[0, 0] = _soluong[0, 0] + StaticUtil.GetDouble(_sl, 0);
                        _soluong[0, 1] = _soluong[0, 1] + StaticUtil.GetDouble(_tt, 0);
                    }

                }
            }
            return _soluong;
        }
        #endregion

        //---- Tính số lượng xuat trong hoa don ban chi tiết 
        #region
        private double[,] TinhSLXuat(int _matHangID, int _donViTinhID, HoaDonBanChiTietBOCollection hdn)
        {
            double[,] _soluong = new double[1, 2];
            int recordCount = hdn.Count;
            if (recordCount > 0)
            {
                for (int i = 0; i < recordCount; i++)
                {
                    if ((hdn[i].MatHangID.Value == _matHangID) & (hdn[i].DonViTinhID.Value == _donViTinhID))
                    {
                        object _sl = hdn[i].SoLuong;
                        object _tt = hdn[i].ThanhTien;
                        _soluong[0, 0] = _soluong[0, 0] + StaticUtil.GetDouble(_sl, 0);
                        _soluong[0, 1] = _soluong[0, 1] + StaticUtil.GetDouble(_tt, 0);
                    }

                }
            }
            return _soluong;
        }

        #endregion

        //---- Tính số lượng chuển đổi kho đến 
        #region

        private double TinhSLDen(int _matHangID, int _donViTinhID, ChuyenKhoBOCollection hdn)
        {
            double _soluong = 0;
            int recordCount = hdn.Count;
            if (recordCount > 0)
            {
                for (int i = 0; i < recordCount; i++)
                {
                    if ((hdn[i].MatHangIDD.Value == _matHangID) & (hdn[i].DonViTinhIDD.Value == _donViTinhID))
                    {
                        object _sl = hdn[i].SoLuongQuyDoi;
                        _soluong = _soluong + StaticUtil.GetDouble(_sl, 0);
                    }

                }
            }
            return _soluong;
        }

        #endregion

        //---- Tính số lượng chuển đổi kho đi 
        #region

        private double TinhSLDi(int _matHangID, int _donViTinhID, ChuyenKhoBOCollection hdn)
        {
            double _soluong = 0;
            int recordCount = hdn.Count;
            if (recordCount > 0)
            {
                for (int i = 0; i < recordCount; i++)
                {
                    if ((hdn[i].MatHangID.Value == _matHangID) & (hdn[i].DonViTinhIDN.Value == _donViTinhID))
                    {
                        object _sl = hdn[i].SoLuongChuyen;
                        _soluong = _soluong + StaticUtil.GetDouble(_sl, 0);
                    }

                }
            }
            return _soluong;
        }

        #endregion

        //---- Tìm mặt hàng trong MatHangBOColl 
        #region
        private string[,] TimMatHang(int _matHangID, MatHangBOCollection hdn)
        {
            string[,] _soluong = new string[1, 2];
            int recordCount = hdn.Count;
            if (recordCount > 0)
            {
                for (int i = 0; i < recordCount; i++)
                {
                    if (hdn[i].MatHangID.Value == _matHangID)
                    {
                        object _ma = hdn[i].MaMatHang;
                        object _ten = hdn[i].Ten;
                        _soluong[0, 0] = _ma.ToString();
                        _soluong[0, 1] = _ten.ToString();
                    }

                }
            }
            return _soluong;
        }
        #endregion

        //---- Tìm giá 
        #region
        private double TimGia(int _matHangID, int _donViTinhID, GiaBOCollection hdn)
        {
            double _soluong = 0;
            int recordCount = hdn.Count;
            if (recordCount > 0)
            {
                for (int i = 0; i < recordCount; i++)
                {
                    if ((hdn[i].MatHangID.Value == _matHangID) & (hdn[i].DonViTinhID.Value == _donViTinhID))
                    {
                        object _sl = hdn[i].GiaBan;
                        _soluong = +StaticUtil.GetDouble(_sl, 0);
                    }

                }
            }
            return _soluong;
        }
        #endregion

        private int kiemtraLuu()
        {
            int tempkiemtra = 1;
            string strError = "";

            if (lookUpEditKhoID.Text.Trim() == "")
            {
                tempkiemtra = 0;
                strError = strError + " ;Vui lòng chọn Kho";
            }


            if (String.Compare(dateEditTungay.DateTime.ToString("yyyy/MM/dd"), dateEditDenngay.DateTime.ToString("yyyy/MM/dd")) > 0)
            {
                tempkiemtra = 0;
                strError = strError + " ;Ngày bắt đầu phải bé thua hoặc bằng ngày cần tổng hợp";
            }

            if (tempkiemtra == 0)
                MessageBox.Show(strError, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return tempkiemtra;
        }

    }
}